﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SiteManager;
using System.IO;

public partial class PresentationForm : System.Web.UI.Page
{
    int DoctorId = 0;
    Manager mgr = new Manager(true, "ConnectionString");
    protected void Page_Load(object sender, EventArgs e)
    {
        //string fileName = Request.QueryString["PresentatonSlide"];
        string fileName = Request.QueryString["ThumpImage"];

        string str_path = getPresentationImageWithURLFormat(fileName, 750, 700, false, "", Session["strHTTP"].ToString());
        imgTag.Text = str_path;
        DoctorId = Convert.ToInt32(Session["DrId"]);
        ShowPresentation(DoctorId);
    }

    private void ShowPresentation(int drID)
    {
        DataSet dshos = mgr.ExecuteQuery("select * from tbl_doctorProfile  where dr_id=" + drID.ToString() + ";", "DocVideo");
        rptrPresendation.DataSource = dshos.Tables[0];
        rptrPresendation.DataBind();

    }
    public string GetThumpNailImage(object photo)
    {
        string p = photo.ToString();
        string str_path = "";
        if (p.Length > 0)
        {
            string AppPath = Request.PhysicalApplicationPath;
            string imgpath = Server.MapPath("~/DrThumpImages/");//AppPath + "Thumbs";

            if (File.Exists(Request.PhysicalApplicationPath + "\\DrThumpImages\\" + photo))
            {
                //string str_path = mgr.getThumbnaleImage(Session["strHttp"].ToString() + "images/Dr_images/" + photo, 80, 100, false, "");

                str_path = getThumbnailImageWithURLFormat(photo.ToString(), 120, 100, false, "", Session["strHTTP"].ToString());
                return str_path;
            }

        }
        return str_path;

    }
    public string getThumbnailImageWithURLFormat(string imgName, int maxWidth, int maxHeight, bool saveImage, string savePath, string baseURL)
    {
        string s;
        double imgHeight, imgWidth;
        //Response.Write(imgName) ;
        s = Server.MapPath("~/DrThumpImages/" + imgName);
        //Response.Write("</br>"+s);
        System.Drawing.Image currentImage = System.Drawing.Image.FromFile(s);
        imgHeight = currentImage.Height;
        imgWidth = currentImage.Width;
        if (imgWidth > maxWidth | imgHeight > maxHeight)
        {
            double deltaWidth = imgWidth - maxWidth;
            double deltaHeight = imgHeight - maxHeight;
            double scaleFactor;
            if (deltaHeight > deltaWidth)
                scaleFactor = maxHeight / imgHeight;
            else
                scaleFactor = maxWidth / imgWidth;
            imgWidth *= scaleFactor;
            imgHeight *= scaleFactor;
        }

        if (saveImage)
        {
            if (savePath == "")
                throw new Exception("must pass a file name");
            currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).Save(Server.MapPath(savePath));
            currentImage.Dispose();
            // return currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).ToString();
        }
        // return currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).ToString();


        // return ("<img src=\"" + baseURL + "Thumbs/" + imgName + "\"" + " height=\"" + imgHeight + "\" width=\"" + imgWidth + "\" border='0' alt=''/>");
        return (baseURL + "DrThumpImages/" + imgName);
    }

    public string getPresentationImageWithURLFormat(string imgName, int maxWidth, int maxHeight, bool saveImage, string savePath, string baseURL)
    {
        string s;
        double imgHeight, imgWidth;
        //Response.Write(imgName) ;
        s = Server.MapPath("~/DrThumpImages/" + imgName);
        //Response.Write("</br>"+s);
        System.Drawing.Image currentImage = System.Drawing.Image.FromFile(s);
        imgHeight = currentImage.Height;
        imgWidth = currentImage.Width;
        if (imgWidth > maxWidth | imgHeight > maxHeight)
        {
            double deltaWidth = imgWidth - maxWidth;
            double deltaHeight = imgHeight - maxHeight;
            double scaleFactor;
            if (deltaHeight > deltaWidth)
                scaleFactor = maxHeight / imgHeight;
            else
                scaleFactor = maxWidth / imgWidth;
            imgWidth *= scaleFactor;
            imgHeight *= scaleFactor;
            imgHeight = imgHeight - 50;
        }

        if (saveImage)
        {
            if (savePath == "")
                throw new Exception("must pass a file name");
            currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero).Save(Server.MapPath(savePath));
            currentImage.Dispose();
        }
        //return currentImage.GetThumbnailImage(Convert.ToInt32(imgWidth), Convert.ToInt32(imgHeight), null, IntPtr.Zero);


        return ("<img src=\"" + baseURL + "DrThumpImages/" + imgName + "\"" + " height=\"" + imgHeight + "\" width=\"" + imgWidth + "\"position:relative" + "\"background-position:center " + "\" border='1' id='imgPres' alt=''/>");
    }
}
